﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Valve.VR;

/// <summary>
/// 监控玩家的动作(Move,Jump和GrabPinch).
/// </summary>

public class Ban3GetMyMoveAction : MonoBehaviour
{
    //moveAction和jumpAction，分别对应移动和跳跃两个动作.
    public SteamVR_Action_Vector2 moveAction = 
        SteamVR_Input.GetAction<SteamVR_Action_Vector2>("platformer","Move");

    public SteamVR_Action_Boolean jumpAction = 
        SteamVR_Input.GetAction<SteamVR_Action_Boolean>("platformer", "Jump");

    //抓取动作.
    public SteamVR_Action_Boolean grabAction =
        SteamVR_Input.GetAction<SteamVR_Action_Boolean>("platformer", "GrabPinch");


    void Update()
    {
        //         if (moveAction != null && moveAction.GetChanged(SteamVR_Input_Sources.Any))
        //         {
        //             Vector2 pos = moveAction.GetAxis(SteamVR_Input_Sources.Any);
        //             Debug.Log("手指在手柄的触摸屏的位置是: " +pos);
        //         }

//         if (jumpAction != null && jumpAction.GetStateDown(SteamVR_Input_Sources.Any))
//         {
//             Debug.LogWarning("跳跃动作触发！");
//         }
// 
//         if (grabAction != null && grabAction.GetStateDown(SteamVR_Input_Sources.Any))
//         {
//             Debug.LogError("抓取动作触发！");
//         }
    }

    /// <summary>
    /// 获得玩家在触发移动动作时的坐标.
    /// </summary>
    /// <returns></returns>
    public Vector2 GetMoveAxis()
    {
        Vector2 pos = Vector2.zero;
        //如果玩家触发了移动动作.
        if (moveAction != null && moveAction.GetChanged(SteamVR_Input_Sources.Any))
        {
            pos = moveAction.GetAxis(SteamVR_Input_Sources.Any);
        }
        
        return pos;
    }
}
